<template>
  <view class="page_pingjia4">
    <view class="kuang">
<!--      <view class="biaoti" v-for="(item,index) in por">{{item.title}}</view>-->
<!--      <view class="xx">-->
<!--        <uni-rate :count="count" v-model="value" size="35" activeColor="#ffaa00"></uni-rate>-->
<!--      </view>-->
      <view class="xkuang">
        <view style="display: flex;">
          <view class="ziti">评分</view>
          <uni-rate :count="5" style="margin-top: 15px; margin-left: 50px;" size="35"
                 activeIcon="heart-fill" inactiveIcon="heart" activeColor="#ffaa00" v-model="evaluate.score">
          </uni-rate>
        </view>
      </view>
      <view>
        <uni-easyinput type="textarea" v-model="evaluate.content" placeholder="请输入内容"></uni-easyinput>
      </view>
      <FileUpload title="实物图片" :associate-form-id="1" associate-form-name="evaluateEdit" @change="changeFiles"></FileUpload>
<!--      <u-upload :fileList="fileList1" style="margin-top: 10px;" @afterRead="afterRead" @delete="deletePic"-->
<!--                name="1" multiple :maxCount="10" action='链接地址'></u-upload>-->
    </view>
    <view class="anniu" v-for="(item,index) in button" :key="index">
      <u-button type="warning" @click="saveEvaluate">{{item.name}}</u-button>
    </view>
  </view>
</template>

<script>
import UniRate from "../../../../uni_modules/uni-rate/components/uni-rate/uni-rate";
import FileUpload from "../../../components/buyer/FileUpload";
import {BASE_URL} from "../../../../api/service";
import {attachmentService} from "../../../../api/buyer/public/attachmentService";
import {EvaluationService} from "../../../../api/buyer/Evaluate/EvaluateService";
export default {
  components: {
    UniRate,
    // start
    FileUpload
  },
  onLoad(option) {
    const order = JSON.parse(decodeURIComponent(option.order));
    this.evaluate.orderId=order.eid;
    this.evaluate.commodityId=order.commodityId;
    console.log(this.evaluate)
  },
    data() {
    return {
      button: [{
        name: '提交'
      }],
      files:[],
      evaluate:{
        score:0,
        content:"",
        userId:uni.getStorageSync('userInfo').eid
      },
    }
  },
  methods: {
    radioChange(n) {
      console.log('radioChange', n);
    },
    changeFiles(items){
      console.log("items",items)
      this.files = items
    },
    saveEvaluate(){
      uni.showLoading({title: '正在提交评论...',mask:true});
      // this.$refs.Loading.hide()

      EvaluationService.saveEvaluation(this.evaluate).then((result)=>{
        uni.hideLoading();
        //图片上传
        if(result.data.eid){
          attachmentService.uploadFiles(this.files,result.data.eid,'evaluation');
        }
        uni.showToast({
          title: '评论成功，即将返回.....',
          duration: 2000
        });
        uni.navigateBack({
          delta: 1,
        })
      }).catch((e)=>{
        uni.hideLoading();
        // uni.showToast("操作失败！")
        uni.showToast({
          title: '网络异常，请稍后再试',
          duration: 2000
        });
      })
    }
  }
}
</script>

<style lang="scss">
.page_pingjia4 {
  width: 100vw;
  height: 80vh;
  background-color: #ffffff;

  .anniu {
    margin-top: 48px;
    width: 90vw;
    margin-left: 20px;
  }

  .niming {
    margin-top: 20px;
  }

  .ziti {
    color: #909090;
    margin-top: 23px;
  }

  .xkuang {
    margin-top: 20px;
    height: 18vh;
    background-color: #FAFAFA;
    padding-left: 30px;
  }

  .xx {
    margin-left: 24%;
    padding-top: 10px;
  }

  .biaoti {
    width: 80%;
    margin: 0 auto;
    text-align: center;
    margin-top: 20px;
  }

  .kuang {
    width: 90vw;
    height: 75vh;
    background-color: #ffffff;
    margin-left: 20px;
  }
}
</style>
